package cn.zirao

import android.view.View
import cn.zirao.model.GasMeterModel
import com.alibaba.fastjson.JSONObject

import zirao.base.activity.BaseActivity
import kotlinx.android.synthetic.main.activity_http_test.*
import zirao.cn.http.MyHttpCallBack
import zirao.cn.http.MyHttpClient
import zirao.cn.http.MyHttpParams

class HttpTestActivity : BaseActivity(R.layout.activity_http_test, 0) {

    override fun initView() {
    }

    override fun initListener() {
        http_test_btn!!.setOnClickListener(this)
    }

    override fun initData() {
    }

    override fun widgetClick(v: View) {
        when (v.id) {
            R.id.http_test_btn -> testHttp()
        }
    }

    private fun testHttp() {
        val url = "http://192.168.18.130:18130/Enterprise_EnnGas/enngas/android/androidInstallAction!queryGasParaByMeterNumber.action"
        var gasMeterModel = GasMeterModel()
        gasMeterModel.meter_number = "B36117060031146"

        val params = MyHttpParams()
        params.put("param", JSONObject.toJSONString(gasMeterModel))

        val callback = object : MyHttpCallBack() {
            override fun onStart() {
                super.onStart()
            }

            override fun onSuccess(p0: String?) {
                http_result_tv.text = p0
            }

            override fun onFailure(p0: String?) {
                http_result_tv.text = p0
            }
        }
        MyHttpClient.getInstance().get(this, url, params, callback)
    }

    override fun onBackPressed() {
        closeActivity(this)
    }
}
